`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    12:19:24 11/19/2020 
// Design Name: 
// Module Name:    GRF 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module GRF(
	 input [31:0]WPC,
    input [4:0] A1,
    input [4:0] A2,
	 input [4:0] write,
    input clk,
    input reset,
    input WE,
    input [31:0] WD,
	 output [31:0] R1,
    output [31:0] R2
    );
	 reg [31:0]grf[31:0];
	 integer i;
	always @(posedge clk)
	begin
		if(reset)
		begin
			for(i=0;i<32;i=i+1)
			begin
				grf[i] <= 0;
			end
		end
		
		else if(WE)
			begin
				grf[write] <= (write==0) ? 0 : WD;
				$display("@%h: $%d <= %h", WPC, write, WD);
			
		end
		
	end
	assign R1 = grf[A1];
	assign R2 = grf[A2];

endmodule
